package com.dcsgo.myTankGameClient.common;

import java.io.Serializable;

/**
 * @author DCSGO
 * @version 1.0
 */

@SuppressWarnings({"all"})
public class Shot implements Runnable, Serializable {
    public int x;
    public int y;
    int direction;
    int speed;
    public boolean visible = true;

    public Shot(int x, int y, int direction, int speed) {
        this.direction = direction;
        this.speed = speed;
        //根据坦克坐标及其方向确定炮弹的初始坐标
        //0-上 1-右 2-下 3-左
        switch (direction) {
            case 0://上
                this.x = x + 20 - 1;
                this.y = y;
                break;
            case 1://右
                this.x = x + 60;
                this.y = y + 20 - 1;
                break;
            case 2://下
                this.x = x + 20 - 1;
                this.y = y + 60;
                break;
            case 3://左
                this.x = x;
                this.y = y + 20 - 1;
                break;
        }
    }

    @Override
    public void run() {
        while (x >= 0 && x <= 1000 &&
                y >= 0 && y <= 750 && visible) {
            switch (direction) {
                case 0://上
                    y -= speed;
                    break;
                case 1://右
                    x += speed;
                    break;
                case 2://下
                    y += speed;
                    break;
                case 3://左
                    x -= speed;
                    break;
            }
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        visible = false;
    }
}


